#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：NoBad 
@File    ：views.py
@Author  ：LYP
@Date    ：2025/11/13 9:51 
@description :
"""
from rest_framework import serializers
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter
from models.models import GuidePage
from tool.base_views import BaseViewSet
from tool.utils import CustomPagination, ApiResponse
from tool.permissions import IsTokenValid


class GuidePageSearilizer(serializers.ModelSerializer):
    class Meta:
        model = GuidePage
        fields = '__all__'


@extend_schema(tags=["引导页"])
@extend_schema_view(
    list=extend_schema(
        summary="获取引导页列表",
        description="返回所有引导页列表",
        responses={200: GuidePageSearilizer(many=True)},
    ),
    create=extend_schema(
        summary="创建引导页",
        description="创建一个引导页",
        request=GuidePageSearilizer,
        responses={201: GuidePageSearilizer},
    )
)
class GuidViewSet(BaseViewSet):
    queryset = GuidePage.objects.all()
    serializer_class = GuidePageSearilizer
    pagination_class = CustomPagination
    # permission_classes = [IsTokenValid]

    def get_queryset(self):

        queryset = super().get_queryset()
        return queryset

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            # 使用自定义分页响应
            return self.get_paginated_response(serializer.data)
        # 如果没有分页，返回普通响应
        serializer = self.get_serializer(queryset, many=True)
        return ApiResponse(serializer.data)

